module ZDDI
    module CLOUD
        def self.open_cloud_page
            ZDDI.browser.link(:class, "cloud").click
            sleep 1
        end
        def self.member_show_list
            ZDDI.browser.div(:id, "toolsBar").button(:class, "showList").click
            sleep 1
        end
        def self.open_manage_page(href="../img/cloud_icon.png")
            open_cloud_page

            puts ZDDI.browser.div(:id, "left").ul(:class, "category").text

        end
        def self.member_exists?(member_name)
            return DNS.elem_exists?(member_name)
        end
        class GROUP 
            def create_member(args)
                group_name = args[:group_name]
                member_name = args[:member_name]
                ip = args[:ip]
                CLOUD.open_cloud_page
                CLOUD.member_show_list
                DNS.popup_right_menu

                ZDDI.browser.div(:id, "popWin").button(:class, "btnGray").click
                ZDDI.browser.div(:id, "popWin").text_field(:name, "groupname").set(group_name)
                ZDDI.browser.div(:id, "popWin").text_field(:name, "name").set(member_name)
                ZDDI.browser.div(:id, "popWin").text_field(:name, "ip").set(ip)
                sleep 1
                ZDDI.browser.div(:id, "popWin").button(:class, "save").click

                if CLOUD.member_exists?(member_name)
                    r = "succeed to create member: #{member_name}\n"
                else
                    r = "failed to create member: #{member_name}\n"
                end
                puts r 
                return r
            end
            def edit_member(args)
            end
            def del_member(args)
                group_name = args[:group_name]
                member_name = args[:member_name]
                CLOUD.open_cloud_page
                CLOUD.member_show_list

                if CLOUD.member_exists?(member_name)
                    ZDDI.browser.button(:class, "del").click
                    sleep 1
                    ZDDI.browser.div(:id, "popWin").button(:class, "ok").click
                    sleep 1
                end
                if !CLOUD.member_exists?(member_name)
                    r = "succeed to del member: #{member_name}\n"
                else
                    r = "failed to del member: #{member_name}\n"
                end
            end
        end
    end
end
